package com.hdax.dmw.item.mapstruct;

import com.hdax.dmw.entity.base.Image;
import com.hdax.dmw.entity.item.Item;
import com.hdax.dmw.item.dtos.ItemDescDto;
import com.hdax.dmw.item.feign.BaseFeign;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper(componentModel = "spring")
public abstract class ItemDescDtoMapper {

    @Autowired
    private BaseFeign baseFeign;

    public String getImgUrl(Long itemId){
        Image image = baseFeign.image(itemId, 2, 1);
        return image == null ? "" : image.getImgUrl();
    }
    public String getAddress(String cinemaName, String areaName){
        System.out.println(cinemaName);
        System.out.println(areaName);
        return cinemaName + " - " + areaName;
    }

    @Mappings({
            @Mapping(target = "imgUrl", expression = "java(getImgUrl(source.getId()))"),
            @Mapping(target = "adress", expression = "java(getAddress(source.getName(),source.getAreaName()))")
    })
    public abstract ItemDescDto toTarget(Item source);
    public abstract List<ItemDescDto> toTargetList(List<Item> sources);
}
